package com.lc.controller;

import com.lc.entity.Order;
import org.springframework.web.bind.annotation.*;

/**
 * Author:LC
 * Version:jdk-8u301
 * Date: 2022/7/19 15:31
 */

@RestController
public class ParamController {

    /**
     * 1. 通过 URL 传参数，GET 请求，参数列表使用@PathVariable（""）
     * 2. 如果是 GET 请求，每个基本参数必须加@RequestParam（""）
     * 3. 如果是 POST 请求，而且是对象集合等参数，必须加@Requestbody 或者@RequestParam
     */

    @GetMapping("/getOneParam")
    public String getOneParam(@RequestParam("name") String name) {
        System.out.println("getOneParam:" + name);
        return "ok";
    }

    @GetMapping("/getTwoParam")
    public String getTwoParam(@RequestParam("name") String name, @RequestParam("age") Integer age) {
        System.out.println("twoParam:" + name + " " + age);
        return "ok";
    }

    @PostMapping("/postOneParamOneObj")
    public String postOneParamOneObj(@RequestBody Order order, @RequestParam("name") String name) {
        System.out.println("postOneParamOneObj:" + order + " " + name);
        return "ok";
    }

}
